
package okdeeplink.sample;

import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.subjects.AsyncSubject;
import okdeeplink.Query;
import okdeeplink.Request;
import okdeeplink.Response;
import okdeeplink.Service;


public class MainActivity extends AppCompatActivity {

    @Service
    SampleService sampleService;
    @Query("key")
    String key;



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       final AsyncSubject<Request> requestSubject = AsyncSubject.create();
        requestSubject.subscribe(new DisposableObserver<Request>() {
            @Override
            public void onNext(@NonNull Request request) {
                Log.d("TAG111", "onNext: ");
            }

            @Override
            public void onError(@NonNull Throwable e) {
                Log.d("TAG111", "onError: "+e.getLocalizedMessage());
            }

            @Override
            public void onComplete() {
                Log.d("TAG111", "onComplete: ");
            }
        });




        findViewById(R.id.Second).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //requestSubject.onComplete();
                sampleService.startSecondActivity("mama",10);
            }
        });

        findViewById(R.id.Capture_Image).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sampleService
                        .startImageCapture()
                        .subscribe(new Consumer<Response>() {
                            @Override
                            public void accept(@NonNull Response response) throws Exception {
                                Intent data = response.getData();
                                int resultCode = response.getResultCode();
                                if (resultCode == RESULT_OK) {
                                    Bitmap imageBitmap = (Bitmap) data.getExtras().get("data");
                                    ImageView imageView = (ImageView) findViewById(R.id.ImageView_Capture_Image);
                                    imageView.setImageBitmap(imageBitmap);
                                }
                            }
                        });
            }
        });

        findViewById(R.id.Tel_Phone).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sampleService.startTel("15108280907");
            }
        });
    }
}
